<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of exitgame
 *
 * @author Dragon.hu add @2015.9.2
 */
defined('BASEPATH') or die('forbidden');

class Exitgame_Controller extends Controller {

	private $inc;
	private $logdb;	//数据库连接
	private $platformList;	//平台列表
	
	function _init() {
		check_level(50, segment(0), segment(1), segment(2, 'index'));
		set_time_limit(0);
		
		$this->inc = $this->config['inc'];
		$this->platformList = $this->inc['platform_list'];
		
        // log数据库
		//$this->logdb = $this->load->database('log_db');

        // log数据库
		$this->logdb = $this->load->database('log_db');
		
		if (false == $this->logdb) {
			//内部有提示错误，在此就不提示了
			 //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
		}	
	}

	function index() {
		$this->view->display("log_role/exitgame/index");
	}

	function flexigrid() {
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();

        $where='eventid=34';
        $sql = "SELECT COUNT(*) AS num FROM gamelog where {$where} ";
		
		$one = $this->logdb->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
			
		$sql = "SELECT * FROM gamelog where {$where}  {$orderby} LIMIT {$offset},{$rp}";
		
		$this->logdb->query($sql);
        $result=$this->logdb->row('default');
		foreach($result as $k => $n)
		{
            $n['time']=date('Y/m/d H:i:s',$n['time']);
            $n['copytype']=$n['param1']>>32;
            $n['copyid']=$n['param1'] & 0x0FFFFFFFF;
            $n['copyresult']=$n['param2']>>32;
            $n['copytime']=$n['param2'] & 0x0FFFFFFFF;

			$rows[] = array('id' => $n['id'], 'cell' => $n);
		}
		
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
		
		echo json_encode($result);
	}


}
